﻿@{
    ViewBag.Title = "Index";
}

<div>Hello @User.Identity.Name</div>
<h1>DemoApp1</h1>
<div class="row">
    <button id="btnTest" value="Test">Test</button>
    <div id="content"></div>

    <button id="btnCode">获取OAuth Code</button>
</div>
@section Scripts {
    <script type="text/javascript">
            $("#btnTest").click(function () {
                $.ajax({
                    type: 'Get',
                    url: '@ViewBag.AjaxCallAuthUrl' + '?clientId=' + '@ViewBag.ClientId',
                    data: {},
                    xhrFields: {
                        // Set this so that will pass authentication cookie to OAuth server
                        withCredentials: true
                    },
                    success: function (data) {
                        if (data != null && data != undefined) {
                            debugger
                            var userName = data.Result;
                            $.ajax({
                                type: 'Get',
                                url: '@Url.Action("GetUserInfo")',
                                headers: { '@ViewBag.HeaderNameForAjaxAuth': data.Result },
                                data: {},
                                success: function (data1) {
                                    $("#content").html("User Name: " + data1.Result);
                                    return;
                                }
                            });
                        }
                    }
                });
            });
    </script>
}

